from entity.model_layers import ModelLayers
from log import log
from util.sqlmapper import SQLManager


class ModelLayersDAO:
    def findAll(self, return_list: bool = False):
        with SQLManager() as db:

            log.info("select * from t_layers order by id")
            res = db.get_all("select * from t_layers order by id")
            if return_list:
                reslist = []
                for item in res:
                    reslist.append(item[1])
                return reslist
            else:
                resdict = {}
                for item in res:
                    resdict[item[0]] = item[1]
                return resdict

    def findOne(self, layer_id: int):
        with SQLManager() as db:
            log.info("select name from t_layers where id = %s" % layer_id)
            return db.get_one("select name from t_layers where id = %s", layer_id)[0]


if __name__ == "__main__":
    print(ModelLayersDAO().findAll(True))
    print(ModelLayersDAO().findOne(2))